package org.example;

import java.util.Scanner;

class TreeNode{
    char val;
    TreeNode leftChild;
    TreeNode rightChild;

    public TreeNode(char val) {
        this.val = val;
    }
}
public class Main {
    //中序遍历
    public static void inOrder(TreeNode root) {
        //设置递归出口
        if(root == null) {
            return;
        }

        //递归遍历左子树
        inOrder(root.leftChild);
        //打印当前结点
        System.out.print(root.val + " ");
        //递归遍历右子树
        inOrder(root.rightChild);
    }

    public static int i = 0;
    public static TreeNode buildTree(String input) {
        //递归出口
        if(i >= input.length()) {
            return null;
        }
        if (input.charAt(i) == '#') {
            return null;
        }
        TreeNode root = new TreeNode(input.charAt(i));
        i++;
        root.leftChild = buildTree(input);
        i++;
        root.rightChild = buildTree(input);
        return root;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        TreeNode root = buildTree(input);
        inOrder(root);
    }
}